package com.ehome.poct.core.controller;

import com.ehome.core.page.Page;
import com.ehome.poct.core.api.dto.DelReportDTO;
import com.ehome.poct.core.api.dto.ReportListDTO;
import com.ehome.poct.core.api.dto.check.BldCheckReportVO;
import com.ehome.poct.core.api.dto.check.CheckReportDTO;
import com.ehome.poct.core.api.dto.check.ProjectNameReportDTO;
import com.ehome.poct.core.api.dto.check.ReportDTO;
import com.ehome.poct.core.api.dto.report.ReportRequestDTO;
import com.ehome.poct.core.api.dto.report.TestReportConfigDTO;
import com.ehome.poct.core.api.virtual.H5ReportService;
import com.ehome.poct.core.api.virtual.ReportService;
import com.ehome.poct.core.api.virtual.WxService;
import com.ehome.poct.core.api.vo.CheckReportVO;
import com.ehome.poct.core.api.vo.ReportDetailVO;
import com.ehome.poct.core.api.vo.ReportDtlVO;
import com.ehome.poct.core.api.vo.report.H5ReportDetailVO;
import com.ehome.web.annotation.RequestLog;
import com.ehome.web.controller.AbstractBaseController;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @author muqiu
 * @date 2022/03/03 10:25
 **/
@Validated
@Api(tags = "报告")
@ApiSupport(author = "muqiu")
@RequestMapping("/report")
@RestController
@AllArgsConstructor
public class ReportController extends AbstractBaseController<CheckReportVO, CheckReportDTO> {
    private final ReportService reportService;
    private final H5ReportService h5ReportService;
    private final WxService wxService;

    @ApiOperation("查询检测列表")
    @ApiOperationSupport(author = "muqiu")
    @PostMapping("/jby/list")
    @RequestLog
    public Page<CheckReportVO> list(@RequestBody @Valid ReportListDTO dto) {
        return reportService.getCheckList(dto);
    }

    @ApiOperation("根据订单号查询血常规报告详情")
    @ApiOperationSupport(author = "muqiu")
    @GetMapping("/by/order/{orderNo}")
    @RequestLog
    public ReportDetailVO getOneByOrderNo(@PathVariable String orderNo) {
        return reportService.getCheckReportByOrderNo(orderNo);
    }

    @ApiOperation("H5-根据订单号查询血常规（单测/三联测）报告详情")
    @ApiOperationSupport(author = "wyc")
    @GetMapping("/h5/bld/{orderNo}")
    @RequestLog
    public H5ReportDetailVO getH5DtlByOrderNo(@PathVariable String orderNo) {
        return h5ReportService.getBldReportByOrderNo(orderNo);
    }

    @ApiOperation("H5-根据金标仪报告ID查询三联测报告详情")
    @ApiOperationSupport(author = "wyc")
    @GetMapping("/h5/ol/jby/{id}")
    @RequestLog
    public H5ReportDetailVO getH5OLDtlByJbyId(@PathVariable Long id) {
        return h5ReportService.getOlReportByJbyId(id);
    }

    @ApiOperation("H5-更新报告code-测试用")
    @ApiOperationSupport(author = "wyc")
    @PutMapping("/h5/code/update/{orderNo}")
    public void getH5OLDtlByJbyId(@PathVariable String orderNo) {
        h5ReportService.updateReportResultCode(orderNo);
    }

    @ApiOperation("根据报告ID查询血常规报告详情")
    @ApiOperationSupport(author = "muqiu")
    @GetMapping("/by/id/{reportId}")
    @RequestLog
    public ReportDetailVO getOne(@PathVariable Long reportId) {
        return reportService.getCheckReport(reportId);
    }

    @ApiOperation("删除金标仪检测报告")
    @ApiOperationSupport(author = "muqiu")
    @DeleteMapping("/del/jby")
    public void delJby(@RequestBody DelReportDTO delReportDTO) {
        reportService.delJby(delReportDTO);
    }

    @ApiOperation("删除血常规检测报告")
    @ApiOperationSupport(author = "muqiu")
    @DeleteMapping("/del/bld/{id}")
    public void delBld(@PathVariable(value = "id") Long id) {
        reportService.delBld(id);
    }

    /**
     * 金标仪单项检测报告详情
     *
     * @param id
     * @return
     */
    @ApiOperation("金标仪单项检测报告详情")
    @ApiOperationSupport(author = "muqiu")
    @GetMapping("/getSingleDetail/{id}")
    public ReportDtlVO getSingleOne(@PathVariable("id") Long id) {
        return reportService.getSingleOne(id);
    }

    /**
     * 联合检测报告详情
     *
     * @param id
     * @return
     */
    @ApiOperation("获取联合检测报告详情")
    @ApiOperationSupport(author = "wyc")
    @GetMapping("/getUnionDetail/{id}")
    public ReportDtlVO getUnionOne(@PathVariable("id") Long id) {
        return reportService.getUnionOne(id);
    }


    @ApiOperation("根据检测数据ID创建血常规报告")
    @ApiOperationSupport(author = "wyc")
    @PostMapping(value = "/bld/{dataId}/{orderNo}/{isPay}")
    @RequestLog
    public BldCheckReportVO createByDataId(@PathVariable Long dataId, @PathVariable String orderNo, @PathVariable Boolean isPay) {
        return reportService.createByDataId(dataId, orderNo, isPay);
    }

    @ApiOperation("获取报告的微信通知链接")
    @ApiOperationSupport(author = "wyc")
    @GetMapping(value = "/notify/url/{reportId}/{type}")
    public String getNotifyUrl(@PathVariable Long reportId, @PathVariable Integer type) {
        return wxService.generateNotifyUrl(reportId, type);
    }

    @ApiOperation("血常规免支付下单后更改金标仪报告状态")
    @ApiOperationSupport(author = "muqiu")
    @PostMapping("/updateReportStatus/{orderNo}")
    public void updateReportStatus(@PathVariable String orderNo) {
        reportService.updateOrderStatus(orderNo);
    }

    /**
     * 报告组成
     *
     * @param reportRequestDTO
     * @return
     */
    @ApiOperation("报告组成")
    @ApiOperationSupport(author = "muqiu")
    @PostMapping(value = "/jby/createReport")
    @RequestLog
    public void createReport(@RequestBody ReportRequestDTO reportRequestDTO) {
        reportService.createReport(reportRequestDTO);
    }

    /**
     * 查询金标仪报告组成
     *
     * @param orderNo
     * @return
     */
    @ApiOperation("查询金标仪报告组成")
    @ApiOperationSupport(author = "muqiu")
    @GetMapping(value = "/jby/getSummaryJby/{orderNo}")
    public List<ReportDTO> getSummaryJby(@PathVariable String orderNo) {
        return reportService.getSummaryJby(orderNo);
    }


    /**
     * 金标仪报告隐藏
     */
    @ApiOperation("金标仪报告隐藏")
    @ApiOperationSupport(author = "muqiu")
    @PostMapping(value = "/jby/reportConfigJby")
    public void reportConfigJby(@RequestBody TestReportConfigDTO testReportConfigDTO) {
        reportService.reportConfigJby(testReportConfigDTO);
    }

    @ApiOperation("血常规报告隐藏")
    @ApiOperationSupport(author = "muqiu")
    @PostMapping(value = "/bld/reportConfigBld")
    public void reportConfigBld(@RequestBody TestReportConfigDTO testReportConfigDTO) {
        reportService.reportConfigBld(testReportConfigDTO);
    }

    @ApiOperation("根据订单号获取简单报表信息")
    @ApiOperationSupport(author = "钟离")
    @GetMapping(value = "/list/{orderNo}")
    public List<ReportDTO> simpleReportList(@PathVariable String orderNo) {
        return reportService.simpleReportList(orderNo);
    }

    @ApiOperation("根据订单号获取项目名称报表信息")
    @ApiOperationSupport(author = "钟离")
    @PostMapping(value = "/projectNameList")
    public List<ProjectNameReportDTO> projectNameList(@RequestBody List<String> orderNos) {
        return reportService.projectNameList(orderNos);
    }
}